Xbasic

handlebars_template_merge Function

Syntax

dim result as c = handlebars_template_merge(template as c, jsonData as c)

Arguments

templateCharacter

The HandleBars template string.

jsonDataCharacter

JSON data to be merged into the template.

Returns

resultCharacter

Returns the merged template and JSON data.

Description

Merges JSON data into a template using Handlebars syntax.

Discussion

Handlebars is a popular, open source templating library. This function takes JSON data and a template (that uses Handlebars syntax) and merges the data into the template.

Example

jsondata = <<%str%
{
    firstname:'Fred',
    lastname : 'Smith'
}
%str%

template = <<%str%
Hello {{firstname}} {{lastname}}
%str%

? handlebars_template_merge(template,jsondata)
= "Hello Fred Smith"

This is just a helper function for the low level NodeServices::HandleBars::RunTemplate() static method.

See Also